import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/14 17:37
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int cnt = 0;
            for (int i = 0; i <= n; i++) {
                if (isWei(i)) {
                    cnt++;
                }
            }
            System.out.println(cnt);
        }
    }
    public static boolean isWei(int n) {
        int pow = n * n;
        if (pow % 10 == n || pow % 100 == n || pow % 1000 == n || pow % 10000 == n ) {
            return true;
        }
        return false;
    }
}
